数据库(2015-08-11).sql 107 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112
  1. 
  2. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_OrdersWageDigital')
  3. BEGIN
  4. DROP VIEW [dbo].View_OrdersWageDigital
  5. END
  6. GO
  7. create view View_OrdersWageDigital
  8. as
  9. select
  10. tb_ErpOrderDigital.Id
  11. , Ordv_Number
  12. ,Ordv_ViceNumber
  13. ,Ordv_DigitalNumber
  14. ,Ord_Number
  15. ,Ord_Type
  16. ,Ord_Class
  17. ,Ord_PhotographyCategory
  18. ,Ord_SeriesName
  19. ,Ord_SeriesPrice
  20. ,(case when Ord_Type = '1' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else (select top 1 Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_Number = Ord_Number) end) as 拍摄名称
  21. ,(select Cus_Name from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as 客户名称
  22. ,(select Cus_Telephone from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as 客户电话
  23. ,Ordv_ClothingName as 礼服师ID
  24. ,dbo.fn_CheckUserIDGetUserName(Ordv_ClothingName) as 礼服师
  25. ,Ordv_ClothingStatus as 礼服师状态
  26. ,Ordv_ClothingTime as 选衣时间
  27. , Ordv_FilmSelectionName as 选片师ID
  28. , dbo.fn_CheckUserIDGetUserName(Ordv_FilmSelectionName) as 选片师
  29. , Ordv_FilmSelectionStatus as 选片状态
  30. , Ordv_FilmSelectionTime as 选片时间
  31. , Ordv_EarlyRepairName as 初修师ID
  32. , dbo.fn_CheckUserIDGetUserName(Ordv_EarlyRepairName) as 初修师
  33. , Ordv_EarlyRepairStatus as 初修状态
  34. , Ordv_EarlyRepairTime as 初修时间
  35. , Ordv_RefinementName as 精修师ID
  36. , dbo.fn_CheckUserIDGetUserName(Ordv_RefinementName)as 精修师
  37. , Ordv_RefinementStatus as 精修状态
  38. , Ordv_RefinementTime as 精修时间
  39. ,Ordv_LookDesignName as 看设计师ID
  40. ,dbo.fn_CheckUserIDGetUserName(Ordv_LookDesignName) as 看设计师
  41. ,Ordv_LookDesignStatus as 看设计状态
  42. ,Ordv_LookDesignTime as 看设计时间
  43. ,Ordv_DesignerName as 设计师ID
  44. ,dbo.fn_CheckUserIDGetUserName(Ordv_DesignerName) as 设计师
  45. ,Ordv_DesignerStatus as 设计状态
  46. , Ordv_DesignerTime as 设计时间
  47. ,(case when (select Count(*) from (select [OPlist_PickupStatus] from [tb_ErpOrderProductList] where [OPlist_ViceNumber]=Ordv_ViceNumber and OPlist_Type = '2' and [OPlist_PickupStatus] = '0') as ta)>0 then '未取' else 'OK' end) AS 取件状态
  48. ,(select top 1 OPlist_PickupTime from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = '2' and OPlist_PickupTime is not null order by OPlist_PickupTime) AS 取件日期
  49. from tb_ErpOrderDigital
  50. left join tb_ErpOrder on tb_ErpOrderDigital.Ordv_Number=tb_ErpOrder.Ord_Number
  51. GO
  52. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_OrdersWagePhotography')
  53. BEGIN
  54. DROP VIEW [dbo].View_OrdersWagePhotography
  55. END
  56. GO
  57. create view View_OrdersWagePhotography
  58. as
  59. SELECT tb_ErpOrdersPhotography.ID
  60. ,Ordpg_Number
  61. ,Ordpg_ViceNumber
  62. ,Ord_Type
  63. ,Ord_Class
  64. ,Ord_PhotographyCategory
  65. ,Ord_SeriesName
  66. ,Ord_SeriesPrice
  67. ,(select Cus_Name from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as 客户名称
  68. ,(select Cus_Telephone from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as 客户电话
  69. ,Ordpg_Sights as 拍摄名称
  70. --,Ordpg_SightsLevel
  71. --,[dbo].[fn_GetClassCodeToName](Ordpg_SightsLevel,Ordpg_SightsLevel) as Sc_ClassName
  72. ,Ordpg_SightsType as 景点类别
  73. ,Ordpg_ApparelQuantity as 服装套数
  74. ,Ordpg_Photographer as 摄影师ID
  75. ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_Photographer) as 摄影师名称
  76. ,Ordpg_PhotographyTime as 拍摄时间
  77. ,Ordpg_PhotographyStatus as 拍摄状态
  78. --,[dbo].fn_CheckOrderPhotographyStatus(Ordpg_PhotographyStatus) as OrdPg_PhotographyStatusName
  79. ,Ordpg_PhotographyAssistant as 摄影助理ID
  80. ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_PhotographyAssistant) as 摄影助理名称
  81. ,Ordpg_MakeupArtist as 化妆师ID
  82. ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_MakeupArtist) as 化妆师名称
  83. ,Ordpg_MakeupAssistant as 化妆助理ID
  84. ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_MakeupAssistant) as 化妆助理名称
  85. ,Ordpg_BootDivision as 引导师ID
  86. ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_BootDivision) as 引导师名称
  87. --,Ordpg_ReservationPhotographyName
  88. --,Ordpg_ReservationPhotographyTime
  89. --,Ordpg_ReservationPhotographyAssistant
  90. --,Ordpg_ReservationMakeupArtist
  91. --,Ordpg_ReservationMakeupAssistant
  92. --,Ordpg_ReservationBootDivision
  93. FROM tb_ErpOrdersPhotography
  94. left join tb_ErpOrder on tb_ErpOrdersPhotography.Ordpg_Number=tb_ErpOrder.Ord_Number
  95. GO
  96. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_ErpSatisfactionReturningMattersSet')
  97. BEGIN
  98. DROP VIEW [dbo].View_ErpSatisfactionReturningMattersSet
  99. END
  100. GO
  101. create view View_ErpSatisfactionReturningMattersSet
  102. as
  103. SELECT tb_ErpSatisfactionReturningMattersSet.ID
  104. ,Sfrms_SurveySetID
  105. ,Sfrms_Contents
  106. ,Sfrms_EnableStatus
  107. ,Sfrms_CreateTime
  108. ,Sfrms_CreateName
  109. ,Sfrms_UpdateTime
  110. ,Sfrms_UpdateName
  111. ,Sfss_Name
  112. ,(CASE sfrms_EnableStatus WHEN '0' THEN '启用' ELSE '不启用' END ) as sfrms_EnableStatusName
  113. FROM tb_ErpSatisfactionReturningMattersSet
  114. left join tb_ErpSatisfactionSurveySet on tb_ErpSatisfactionReturningMattersSet.Sfrms_SurveySetID=tb_ErpSatisfactionSurveySet.ID
  115. GO
  116. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_ErpSatisfactionSurvey')
  117. BEGIN
  118. DROP VIEW [dbo].View_ErpSatisfactionSurvey
  119. END
  120. GO
  121. create view View_ErpSatisfactionSurvey
  122. as
  123. SELECT tb_ErpSatisfactionSurvey.ID
  124. ,Sfs_OrderNumber
  125. ,Sfs_OrderNumberDeputy
  126. ,Sfs_EmployeeID
  127. ,(select [User_Name] from tb_ErpUser where Sfs_EmployeeID=User_EmployeeID) as Sfs_EmployeeName
  128. ,Sfs_Type
  129. ,Sfs_SurveySetID
  130. ,Sfss_Name as Sfs_SurveySetName
  131. ,Sfs_ReturningMattersSetID
  132. ,Sfrms_Contents
  133. ,Sfs_RatingSetID
  134. ,Sfrs_Name as Sfs_RatingSetName
  135. ,Sfs_Remark
  136. ,Sfs_CreateName as Sfs_CreateNameID
  137. ,(select [User_Name] from tb_ErpUser where Sfs_CreateName=User_EmployeeID) as Sfs_CreateName
  138. ,Sfs_CreateTime
  139. ,Sfs_UpdateTime
  140. ,Sfs_UpdateName as Sfs_UpdateNameID
  141. ,(select [User_Name] from tb_ErpUser where Sfs_UpdateName=User_EmployeeID) as Sfs_UpdateName
  142. ,Ord_CustomerName1
  143. ,Ord_CustomerSex1
  144. ,Ord_CustomerTelephone1
  145. ,Sfrs_Scores
  146. ,(select count(id) from tb_ErpSatisfactionReturningMattersSet where Sfrms_SurveySetID=Sfs_SurveySetID) as SatisfactionReturningMattersSetCount
  147. FROM tb_ErpSatisfactionSurvey
  148. left join tb_ErpSatisfactionSurveySet on Sfs_SurveySetID=tb_ErpSatisfactionSurveySet.ID
  149. left join tb_ErpSatisfactionReturningMattersSet on Sfs_ReturningMattersSetID=tb_ErpSatisfactionReturningMattersSet.ID
  150. left join tb_ErpSatisfactionRatingSet on Sfs_RatingSetID=tb_ErpSatisfactionRatingSet.ID
  151. left join View_Customer_PaymentOrdersTwo on Sfs_OrderNumber=Ord_Number
  152. GO
  153. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_OtherCustomers')
  154. BEGIN
  155. DROP VIEW [dbo].View_OtherCustomers
  156. END
  157. GO
  158. Create View View_OtherCustomers
  159. as
  160. SELECT distinct
  161. Tsorder_CustomerNumber
  162. , [Tsorder_CustomerName]
  163. ,[Tsorder_Telephone]
  164. ,Cus_NamePinyin
  165. FROM Vw_TwoSalesOrder
  166. GO
  167. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_Customer_PaymentOrdersTwo')
  168. BEGIN
  169. DROP VIEW [dbo].View_Customer_PaymentOrdersTwo
  170. END
  171. GO
  172. Create view [dbo].[View_Customer_PaymentOrdersTwo]
  173. as
  174. select ID,
  175. Ord_Number,
  176. Ord_DividedShop,
  177. Ord_Type,
  178. Ord_SeriesName,
  179. Ord_SeriesPrice,
  180. Ord_Class,
  181. Ord_CustomerListID,
  182. Ord_MainContact,
  183. (select Cus_Name from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as Ord_CustomerName1,
  184. (select Cus_Sex from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as Ord_CustomerSex1,
  185. (select Cus_Telephone from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as Ord_CustomerTelephone1,
  186. (CASE Ord_Type
  187. WHEN '0' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1))
  188. WHEN '1' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1))
  189. ELSE '' END ) as Ord_CustomerListID2 ,
  190. (select Cus_Name from tb_ErpCustomer where (CASE Ord_Type
  191. WHEN '0' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1))
  192. WHEN '1' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1))
  193. ELSE '' END )=Cus_CustomerNumber) as Ord_CustomerName2,
  194. (select Cus_Telephone from tb_ErpCustomer where (CASE Ord_Type
  195. WHEN '0' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1))
  196. WHEN '1' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1))
  197. ELSE '' END )=Cus_CustomerNumber) as Ord_CustomerTelephone2,
  198. (select stuff((select ','+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('')),1,1,'')) as Ord_OrdersPerson,
  199. (select [Cus_NamePinyin] from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) AS name1,
  200. ((select [Cus_NamePinyin] from tb_ErpCustomer where (CASE Ord_Type
  201. WHEN '0' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1))
  202. WHEN '1' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1))
  203. ELSE '' END )=Cus_CustomerNumber)) AS name2,
  204. (select stuff((select ','+ OrdPe_OrdersPerson from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('')),1,1,'')) as Ord_OrdersPersonID,
  205. Ord_CreateDatetime
  206. ,( SELECT count(id) FROM tb_ErpOrderProductList where OPlist_OrderNumber=Ord_Number and OPlist_PickupStatus=0) as PickupStatusCount
  207. from tb_ErpOrder
  208. GO
  209. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_ErpPieceCommissionRecords')
  210. BEGIN
  211. DROP VIEW [dbo].View_ErpPieceCommissionRecords
  212. END
  213. GO
  214. Create view [dbo].[View_ErpPieceCommissionRecords]
  215. as
  216. SELECT tb_ErpPieceCommissionRecords.ID
  217. ,Pcr_OrderNumber
  218. ,Pcr_DigitalDivision
  219. ,Pcr_Date
  220. ,Pcr_CompletionContents
  221. ,Pcr_Quantity
  222. ,Pcr_CreateTime
  223. ,Pcr_EntryPeople
  224. ,Pcr_Type
  225. ,(select [User_Name] from tb_ErpUser where Pcr_DigitalDivision=User_EmployeeID) as Pcr_DigitalDivisionName
  226. ,[dbo].[fn_GetClassCodeToName](Pcr_CompletionContents,Pcr_CompletionContents) as Pcr_CompletionContentsName
  227. ,(select [User_Name] from tb_ErpUser where Pcr_EntryPeople=User_EmployeeID) as Pcr_EntryPeopleName
  228. ,Ord_Type
  229. ,Ord_Class
  230. ,(select Cus_Name from tempTB_AggregationCustomer where Pcr_OrderNumber=GP_OrderNumber) as Cus_Name
  231. ,(select Cus_Telephone from tempTB_AggregationCustomer where Pcr_OrderNumber=GP_OrderNumber) as Cus_Telephone
  232. ,Ord_SeriesName
  233. ,Ord_SeriesPrice
  234. FROM tb_ErpPieceCommissionRecords
  235. left join tb_ErpOrder on tb_ErpPieceCommissionRecords.Pcr_OrderNumber=tb_ErpOrder.Ord_Number
  236. GO
  237. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_OrdersWagePaymentRecords')
  238. BEGIN
  239. DROP VIEW [dbo].View_OrdersWagePaymentRecords
  240. END
  241. GO
  242. Create VIEW [dbo].[View_OrdersWagePaymentRecords]
  243. AS
  244. SELECT View_ErpPayment.ID
  245. ,Pay_OrdNumber
  246. ,Pay_AmountOf
  247. ,Pay_OpenSingle
  248. ,Pay_ThePayee
  249. ,Pay_PaymentMethod
  250. ,Pay_OrdersLocation
  251. ,Pay_ReceivableProject
  252. ,Pay_CustomNumber
  253. ,Pay_Remark
  254. ,convert(varchar(10),Pay_CreateDatetime,120) as Pay_CreateDatetime
  255. ,Pay_Category
  256. ,Pay_TwoPinsCategory
  257. ,Pay_UserName
  258. ,Pay_ThePayeeName
  259. ,Pay_PaymentMethodName
  260. ,Pay_TwoPinsCategoryName
  261. ,Pay_FinancialAuditdPeople
  262. ,Pay_FinancialAudit
  263. ,Pay_FinancialAuditdPeopleName
  264. ,Pay_ShootingName
  265. ,Ord_Number
  266. ,Ord_DividedShop
  267. ,Ord_Type
  268. ,Ord_Class
  269. , Ord_CustomerName1
  270. ,name1
  271. ,Ord_CustomerTelephone1
  272. ,(select Tsorder_Name from tb_ErpTwoSalesOrder where Pay_OrdNumber= Tsorder_Number) as Tsorder_Name
  273. ,(select Cus_Name from View_DressSaleRentalOrder where Pay_OrdNumber=Dsro_Number) as Cus_Name
  274. ,(select Tsorder_CustomerName from View_TwoSalesOrder where Pay_OrdNumber= Tsorder_Number) as Tsorder_CustomerName
  275. ,Ord_CreateDatetime
  276. ,(select OrdPe_Type from tb_ErpOrdersPerson where OrdPe_OrderNumber=Pay_OrdNumber and OrdPe_OrdersPerson=Pay_OpenSingle) as OrdPe_Type
  277. ,Ord_SeriesName
  278. FROM View_ErpPayment
  279. left join View_Customer_PaymentOrdersTwo on View_ErpPayment.Pay_OrdNumber=View_Customer_PaymentOrdersTwo.Ord_Number
  280. GO
  281. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_ErpSatisfactionSurvey')
  282. BEGIN
  283. DROP VIEW [dbo].View_ErpSatisfactionSurvey
  284. END
  285. GO
  286. Create view [dbo].[View_ErpSatisfactionSurvey]
  287. as
  288. SELECT tb_ErpSatisfactionSurvey.ID
  289. ,Sfs_OrderNumber
  290. ,Sfs_OrderNumberDeputy
  291. ,Sfs_EmployeeID
  292. ,(select User_Name from tb_ErpUser where Sfs_EmployeeID=User_EmployeeID) as Sfs_EmployeeName
  293. ,Sfs_Type
  294. ,Sfs_SurveySetID
  295. ,Sfss_Name as Sfs_SurveySetName
  296. ,Sfs_ReturningMattersSetID
  297. ,Sfrms_Contents
  298. ,Sfs_RatingSetID
  299. ,Sfrs_Name as Sfs_RatingSetName
  300. ,Sfs_Remark
  301. ,Sfs_CreateName as Sfs_CreateNameID
  302. ,(select User_Name from tb_ErpUser where Sfs_CreateName=User_EmployeeID) as Sfs_CreateName
  303. ,Sfs_CreateTime
  304. ,Sfs_UpdateTime
  305. ,Sfs_UpdateName as Sfs_UpdateNameID
  306. ,(select User_Name from tb_ErpUser where Sfs_UpdateName=User_EmployeeID) as Sfs_UpdateName
  307. , Ord_CustomerName1
  308. ,name1
  309. ,Ord_CustomerTelephone1
  310. ,Sfrs_Scores
  311. ,(select count(id) from tb_ErpSatisfactionReturningMattersSet where Sfrms_SurveySetID=Sfs_SurveySetID) as SatisfactionReturningMattersSetCount
  312. FROM tb_ErpSatisfactionSurvey
  313. left join tb_ErpSatisfactionSurveySet on Sfs_SurveySetID=tb_ErpSatisfactionSurveySet.ID
  314. left join tb_ErpSatisfactionReturningMattersSet on Sfs_ReturningMattersSetID=tb_ErpSatisfactionReturningMattersSet.ID
  315. left join tb_ErpSatisfactionRatingSet on Sfs_RatingSetID=tb_ErpSatisfactionRatingSet.ID
  316. left join View_Customer_PaymentOrdersTwo on Sfs_OrderNumber=Ord_Number
  317. GO
  318. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_OrdersWageDigital')
  319. BEGIN
  320. DROP VIEW [dbo].View_OrdersWageDigital
  321. END
  322. GO
  323. Create view [dbo].[View_OrdersWageDigital]
  324. as
  325. select
  326. tb_ErpOrderDigital.Id
  327. , Ordv_Number
  328. ,Ordv_ViceNumber
  329. ,Ordv_DigitalNumber
  330. ,Ord_Number
  331. ,Ord_Type
  332. ,Ord_Class
  333. ,Ord_PhotographyCategory
  334. ,Ord_SeriesName
  335. ,Ord_SeriesPrice
  336. ,(case when Ord_Type = '1' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else (select top 1 Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_Number = Ord_Number) end) as 拍摄名称
  337. ,(select Cus_Name from tempTB_AggregationCustomer where Ord_Number=GP_OrderNumber) as 客户名称
  338. ,(select Cus_Telephone from tempTB_AggregationCustomer where Ord_Number=GP_OrderNumber) as 客户电话
  339. ,Ordv_ClothingName as 礼服师ID
  340. ,dbo.fn_CheckUserIDGetUserName(Ordv_ClothingName) as 礼服师
  341. ,Ordv_ClothingStatus as 礼服师状态
  342. ,Ordv_ClothingTime as 选衣时间
  343. , Ordv_FilmSelectionName as 选片师ID
  344. , dbo.fn_CheckUserIDGetUserName(Ordv_FilmSelectionName) as 选片师
  345. , Ordv_FilmSelectionStatus as 选片状态
  346. , Ordv_FilmSelectionTime as 选片时间
  347. , Ordv_EarlyRepairName as 初修师ID
  348. , dbo.fn_CheckUserIDGetUserName(Ordv_EarlyRepairName) as 初修师
  349. , Ordv_EarlyRepairStatus as 初修状态
  350. , Ordv_EarlyRepairTime as 初修时间
  351. , Ordv_RefinementName as 精修师ID
  352. , dbo.fn_CheckUserIDGetUserName(Ordv_RefinementName)as 精修师
  353. , Ordv_RefinementStatus as 精修状态
  354. , Ordv_RefinementTime as 精修时间
  355. ,Ordv_LookDesignName as 看设计师ID
  356. ,dbo.fn_CheckUserIDGetUserName(Ordv_LookDesignName) as 看设计师
  357. ,Ordv_LookDesignStatus as 看设计状态
  358. ,Ordv_LookDesignTime as 看设计时间
  359. ,Ordv_DesignerName as 设计师ID
  360. ,dbo.fn_CheckUserIDGetUserName(Ordv_DesignerName) as 设计师
  361. ,Ordv_DesignerStatus as 设计状态
  362. , Ordv_DesignerTime as 设计时间
  363. ,(case when (select Count(*) from (select [OPlist_PickupStatus] from [tb_ErpOrderProductList] where [OPlist_ViceNumber]=Ordv_ViceNumber and OPlist_Type = '2' and [OPlist_PickupStatus] = '0') as ta)>0 then '未取' else 'OK' end) AS 取件状态
  364. ,(select top 1 OPlist_PickupTime from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = '2' and OPlist_PickupTime is not null order by OPlist_PickupTime) AS 取件日期
  365. ,(case Ord_Type
  366. when 0 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  367. when 1 then (select count(id) as id from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  368. when 2 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  369. else '' end) as 未拍个数
  370. from tb_ErpOrderDigital
  371. left join tb_ErpOrder on tb_ErpOrderDigital.Ordv_Number=tb_ErpOrder.Ord_Number
  372. GO
  373. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_OrdersWagePhotography')
  374. BEGIN
  375. DROP VIEW [dbo].View_OrdersWagePhotography
  376. END
  377. GO
  378. Create view [dbo].[View_OrdersWagePhotography]
  379. as
  380. SELECT tb_ErpOrdersPhotography.ID
  381. ,Ordpg_Number
  382. ,Ordpg_ViceNumber
  383. ,Ord_Type
  384. ,Ord_Class
  385. ,Ord_PhotographyCategory
  386. ,Ord_SeriesName
  387. ,Ord_SeriesPrice
  388. ,(select Cus_Name from tempTB_AggregationCustomer where Ord_Number=GP_OrderNumber) as 客户名称
  389. ,(select Cus_Telephone from tempTB_AggregationCustomer where Ord_Number=GP_OrderNumber) as 客户电话
  390. ,Ordpg_Sights as 拍摄名称
  391. --,Ordpg_SightsLevel
  392. --,[dbo].[fn_GetClassCodeToName](Ordpg_SightsLevel,Ordpg_SightsLevel) as Sc_ClassName
  393. ,Ordpg_SightsType as 景点类别
  394. ,Ordpg_ApparelQuantity as 服装套数
  395. ,Ordpg_Photographer as 摄影师ID
  396. ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_Photographer) as 摄影师名称
  397. ,Ordpg_PhotographyTime as 拍摄时间
  398. ,Ordpg_PhotographyStatus as 拍摄状态
  399. --,[dbo].fn_CheckOrderPhotographyStatus(Ordpg_PhotographyStatus) as OrdPg_PhotographyStatusName
  400. ,Ordpg_PhotographyAssistant as 摄影助理ID
  401. ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_PhotographyAssistant) as 摄影助理名称
  402. ,Ordpg_MakeupArtist as 化妆师ID
  403. ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_MakeupArtist) as 化妆师名称
  404. ,Ordpg_MakeupAssistant as 化妆助理ID
  405. ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_MakeupAssistant) as 化妆助理名称
  406. ,Ordpg_BootDivision as 引导师ID
  407. ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_BootDivision) as 引导师名称
  408. --,Ordpg_ReservationPhotographyName
  409. --,Ordpg_ReservationPhotographyTime
  410. --,Ordpg_ReservationPhotographyAssistant
  411. --,Ordpg_ReservationMakeupArtist
  412. --,Ordpg_ReservationMakeupAssistant
  413. --,Ordpg_ReservationBootDivision
  414. FROM tb_ErpOrdersPhotography
  415. left join tb_ErpOrder on tb_ErpOrdersPhotography.Ordpg_Number=tb_ErpOrder.Ord_Number
  416. GO
  417. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_Customer_PaymentOrders')
  418. BEGIN
  419. DROP VIEW [dbo].Vw_Customer_PaymentOrders
  420. END
  421. GO
  422. Create view [dbo].Vw_Customer_PaymentOrders
  423. as
  424. select
  425. tb_ErpOrder.ID
  426. ,Ord_Number
  427. ,Ord_DividedShop
  428. ,Ord_Type
  429. ,Ord_PhotographyCategory
  430. ,Ord_SeriesName
  431. ,Ord_SeriesPrice
  432. ,Ord_Class
  433. ,GP_OrderNumber
  434. ,GP_CustomerGroupID
  435. ,Cus_Name
  436. ,Cus_Name_py
  437. ,Cus_Telephone
  438. ,M_Cus_CustomerNumber
  439. ,(select stuff((select ','+ OrdPe_OrdersPerson from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('')),1,1,'')) as Ord_OrdersPersonID
  440. ,(select stuff((select ','+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('')),1,1,'')) as Ord_OrdersPerson
  441. ,Ord_CreateDatetime
  442. ,( SELECT count(id) FROM tb_ErpOrderProductList where OPlist_OrderNumber=Ord_Number and OPlist_PickupStatus=0) as PickupStatusCount
  443. from tb_ErpOrder
  444. left join tempTB_AggregationCustomer on Ord_Number=GP_OrderNumber
  445. GO
  446. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_OrdersWagePaymentRecords')
  447. BEGIN
  448. DROP VIEW [dbo].Vw_OrdersWagePaymentRecords
  449. END
  450. GO
  451. Create VIEW [dbo].Vw_OrdersWagePaymentRecords
  452. AS
  453. SELECT View_ErpPayment.ID
  454. ,Pay_OrdNumber
  455. ,Pay_AmountOf
  456. ,Pay_OpenSingle
  457. ,Pay_ThePayee
  458. ,Pay_PaymentMethod
  459. ,Pay_OrdersLocation
  460. ,Pay_ReceivableProject
  461. ,Pay_CustomNumber
  462. ,Pay_Remark
  463. ,convert(varchar(10),Pay_CreateDatetime,120) as Pay_CreateDatetime
  464. ,Pay_Category
  465. ,Pay_TwoPinsCategory
  466. ,Pay_UserName
  467. ,Pay_ThePayeeName
  468. ,Pay_PaymentMethodName
  469. ,Pay_TwoPinsCategoryName
  470. ,Pay_FinancialAuditdPeople
  471. ,Pay_FinancialAudit
  472. ,Pay_FinancialAuditdPeopleName
  473. ,Pay_ShootingName
  474. ,Ord_Number
  475. ,Ord_DividedShop
  476. ,Ord_Type
  477. ,Ord_Class
  478. ,Cus_Name as Ord_CustomerName1
  479. ,Cus_Name_py
  480. ,Cus_Telephone
  481. ,(select Tsorder_Name from tb_ErpTwoSalesOrder where Pay_OrdNumber= Tsorder_Number) as Tsorder_Name
  482. ,(select Cus_Name from View_DressSaleRentalOrder where Pay_OrdNumber=Dsro_Number) as Cus_Name
  483. ,(select Tsorder_CustomerName from View_TwoSalesOrder where Pay_OrdNumber= Tsorder_Number) as Tsorder_CustomerName
  484. ,Ord_CreateDatetime
  485. ,(select OrdPe_Type from tb_ErpOrdersPerson where OrdPe_OrderNumber=Pay_OrdNumber and OrdPe_OrdersPerson=Pay_OpenSingle) as OrdPe_Type
  486. ,Ord_SeriesName
  487. ,Ord_PhotographyCategory
  488. FROM View_ErpPayment
  489. left join Vw_Customer_PaymentOrders on View_ErpPayment.Pay_OrdNumber=Vw_Customer_PaymentOrders.Ord_Number
  490. GO
  491. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_ErpPieceCommissionRecords')
  492. BEGIN
  493. DROP VIEW [dbo].Vw_ErpPieceCommissionRecords
  494. END
  495. GO
  496. Create view [dbo].Vw_ErpPieceCommissionRecords
  497. as
  498. SELECT tb_ErpPieceCommissionRecords.ID
  499. ,Pcr_OrderNumber
  500. ,Pcr_DigitalDivision
  501. ,Pcr_Date
  502. ,Pcr_CompletionContents
  503. ,Pcr_Quantity
  504. ,Pcr_CreateTime
  505. ,Pcr_EntryPeople
  506. ,Pcr_Type
  507. ,(select [User_Name] from tb_ErpUser where Pcr_DigitalDivision=User_EmployeeID) as Pcr_DigitalDivisionName
  508. ,[dbo].[fn_GetClassCodeToName](Pcr_CompletionContents,Pcr_CompletionContents) as Pcr_CompletionContentsName
  509. ,(select [User_Name] from tb_ErpUser where Pcr_EntryPeople=User_EmployeeID) as Pcr_EntryPeopleName
  510. ,Ord_Type
  511. ,Ord_Class
  512. ,(select Cus_Name from tempTB_AggregationCustomer where Pcr_OrderNumber=GP_OrderNumber) as Cus_Name
  513. ,(select Cus_Telephone from tempTB_AggregationCustomer where Pcr_OrderNumber=GP_OrderNumber) as Cus_Telephone
  514. ,Ord_SeriesName
  515. ,Ord_SeriesPrice
  516. ,Pcr_Quantity*(select Wcs_Percentage from tb_ErpWageCommissionSet where Pcr_CompletionContents=Wcs_TypeCode) as 总价格
  517. FROM tb_ErpPieceCommissionRecords
  518. left join tb_ErpOrder on tb_ErpPieceCommissionRecords.Pcr_OrderNumber=tb_ErpOrder.Ord_Number
  519. GO
  520. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_ErpSatisfactionSurvey')
  521. BEGIN
  522. DROP VIEW [dbo].Vw_ErpSatisfactionSurvey
  523. END
  524. GO
  525. Create view [dbo].Vw_ErpSatisfactionSurvey
  526. as
  527. SELECT tb_ErpSatisfactionSurvey.ID
  528. ,Sfs_OrderNumber
  529. ,Sfs_OrderNumberDeputy
  530. ,Sfs_EmployeeID
  531. ,(select User_Name from tb_ErpUser where Sfs_EmployeeID=User_EmployeeID) as Sfs_EmployeeName
  532. ,Sfs_Type
  533. ,Sfs_SurveySetID
  534. ,Sfss_Name as Sfs_SurveySetName
  535. ,Sfs_ReturningMattersSetID
  536. ,Sfrms_Contents
  537. ,Sfs_RatingSetID
  538. ,Sfrs_Name as Sfs_RatingSetName
  539. ,Sfs_Remark
  540. ,Sfs_CreateName as Sfs_CreateNameID
  541. ,(select User_Name from tb_ErpUser where Sfs_CreateName=User_EmployeeID) as Sfs_CreateName
  542. ,Sfs_CreateTime
  543. ,Sfs_UpdateTime
  544. ,Sfs_UpdateName as Sfs_UpdateNameID
  545. ,(select User_Name from tb_ErpUser where Sfs_UpdateName=User_EmployeeID) as Sfs_UpdateName
  546. ,Cus_Name
  547. ,Cus_Name_py
  548. ,Cus_Telephone
  549. ,Sfrs_Scores
  550. ,(select count(id) from tb_ErpSatisfactionReturningMattersSet where Sfrms_SurveySetID=Sfs_SurveySetID) as SatisfactionReturningMattersSetCount
  551. FROM tb_ErpSatisfactionSurvey
  552. left join tb_ErpSatisfactionSurveySet on Sfs_SurveySetID=tb_ErpSatisfactionSurveySet.ID
  553. left join tb_ErpSatisfactionReturningMattersSet on Sfs_ReturningMattersSetID=tb_ErpSatisfactionReturningMattersSet.ID
  554. left join tb_ErpSatisfactionRatingSet on Sfs_RatingSetID=tb_ErpSatisfactionRatingSet.ID
  555. left join Vw_Customer_PaymentOrders on Sfs_OrderNumber=Ord_Number
  556. GO
  557. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_OrdersWageDigital')
  558. BEGIN
  559. DROP VIEW [dbo].Vw_OrdersWageDigital
  560. END
  561. GO
  562. Create view [dbo].Vw_OrdersWageDigital
  563. as
  564. select
  565. tb_ErpOrderDigital.Id
  566. , Ordv_Number
  567. ,Ordv_ViceNumber
  568. ,Ordv_DigitalNumber
  569. ,Ord_Number
  570. ,Ord_Type
  571. ,Ord_Class
  572. ,Ord_PhotographyCategory
  573. ,Ord_SeriesName
  574. ,Ord_SeriesPrice
  575. ,(case when Ord_Type = '1' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else (select top 1 Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_Number = Ord_Number) end) as 拍摄名称
  576. ,(select Cus_Name from tempTB_AggregationCustomer where Ord_Number=GP_OrderNumber) as 客户名称
  577. ,(select Cus_Telephone from tempTB_AggregationCustomer where Ord_Number=GP_OrderNumber) as 客户电话
  578. ,Ordv_ClothingName as 礼服师ID
  579. ,dbo.fn_CheckUserIDGetUserName(Ordv_ClothingName) as 礼服师
  580. ,Ordv_ClothingStatus as 礼服师状态
  581. ,Ordv_ClothingTime as 选衣时间
  582. , Ordv_FilmSelectionName as 选片师ID
  583. , dbo.fn_CheckUserIDGetUserName(Ordv_FilmSelectionName) as 选片师
  584. , Ordv_FilmSelectionStatus as 选片状态
  585. , Ordv_FilmSelectionTime as 选片时间
  586. , Ordv_EarlyRepairName as 初修师ID
  587. , dbo.fn_CheckUserIDGetUserName(Ordv_EarlyRepairName) as 初修师
  588. , Ordv_EarlyRepairStatus as 初修状态
  589. , Ordv_EarlyRepairTime as 初修时间
  590. , Ordv_RefinementName as 精修师ID
  591. , dbo.fn_CheckUserIDGetUserName(Ordv_RefinementName)as 精修师
  592. , Ordv_RefinementStatus as 精修状态
  593. , Ordv_RefinementTime as 精修时间
  594. ,Ordv_LookDesignName as 看设计师ID
  595. ,dbo.fn_CheckUserIDGetUserName(Ordv_LookDesignName) as 看设计师
  596. ,Ordv_LookDesignStatus as 看设计状态
  597. ,Ordv_LookDesignTime as 看设计时间
  598. ,Ordv_DesignerName as 设计师ID
  599. ,dbo.fn_CheckUserIDGetUserName(Ordv_DesignerName) as 设计师
  600. ,Ordv_DesignerStatus as 设计状态
  601. , Ordv_DesignerTime as 设计时间
  602. ,(case when (select Count(*) from (select [OPlist_PickupStatus] from [tb_ErpOrderProductList] where [OPlist_ViceNumber]=Ordv_ViceNumber and OPlist_Type = '2' and [OPlist_PickupStatus] = '0') as ta)>0 then '未取' else 'OK' end) AS 取件状态
  603. ,(select top 1 OPlist_PickupTime from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = '2' and OPlist_PickupTime is not null order by OPlist_PickupTime) AS 取件日期
  604. from tb_ErpOrderDigital
  605. left join tb_ErpOrder on tb_ErpOrderDigital.Ordv_Number=tb_ErpOrder.Ord_Number
  606. GO
  607. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_OrdersWagePhotography')
  608. BEGIN
  609. DROP VIEW [dbo].Vw_OrdersWagePhotography
  610. END
  611. GO
  612. Create view [dbo].Vw_OrdersWagePhotography
  613. as
  614. SELECT tb_ErpOrdersPhotography.ID
  615. ,Ordpg_Number
  616. ,Ordpg_ViceNumber
  617. ,Ord_Type
  618. ,Ord_Class
  619. ,Ord_PhotographyCategory
  620. ,Ord_SeriesName
  621. ,Ord_SeriesPrice
  622. ,(select Cus_Name from tempTB_AggregationCustomer where Ord_Number=GP_OrderNumber) as 客户名称
  623. ,(select Cus_Telephone from tempTB_AggregationCustomer where Ord_Number=GP_OrderNumber) as 客户电话
  624. ,Ordpg_Sights as 拍摄名称
  625. --,Ordpg_SightsLevel
  626. --,[dbo].[fn_GetClassCodeToName](Ordpg_SightsLevel,Ordpg_SightsLevel) as Sc_ClassName
  627. ,Ordpg_SightsType as 景点类别
  628. ,Ordpg_ApparelQuantity as 服装套数
  629. ,Ordpg_Photographer as 摄影师ID
  630. ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_Photographer) as 摄影师名称
  631. ,Ordpg_PhotographyTime as 拍摄时间
  632. ,Ordpg_PhotographyStatus as 拍摄状态
  633. --,[dbo].fn_CheckOrderPhotographyStatus(Ordpg_PhotographyStatus) as OrdPg_PhotographyStatusName
  634. ,Ordpg_PhotographyAssistant as 摄影助理ID
  635. ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_PhotographyAssistant) as 摄影助理名称
  636. ,Ordpg_MakeupArtist as 化妆师ID
  637. ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_MakeupArtist) as 化妆师名称
  638. ,Ordpg_MakeupAssistant as 化妆助理ID
  639. ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_MakeupAssistant) as 化妆助理名称
  640. ,Ordpg_BootDivision as 引导师ID
  641. ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_BootDivision) as 引导师名称
  642. --,Ordpg_ReservationPhotographyName
  643. --,Ordpg_ReservationPhotographyTime
  644. --,Ordpg_ReservationPhotographyAssistant
  645. --,Ordpg_ReservationMakeupArtist
  646. --,Ordpg_ReservationMakeupAssistant
  647. --,Ordpg_ReservationBootDivision
  648. FROM tb_ErpOrdersPhotography
  649. left join tb_ErpOrder on tb_ErpOrdersPhotography.Ordpg_Number=tb_ErpOrder.Ord_Number
  650. GO
  651. update tb_ErpSystemCategory set Sc_ClassName='提成点方案' where Sc_ClassCode='BEBBAFACDCCFBJFI'
  652. GO
  653. if not exists
  654. (select * from syscolumns where id=object_id('tb_ErpPayment') and name='Pay_Type')
  655. begin
  656. alter table tb_ErpPayment add Pay_Type int
  657. end
  658. GO
  659. if not exists
  660. (select * from syscolumns where id=object_id('tb_ErpTwoSalesOrder') and name='Tsorder_CustomerNumber')
  661. begin
  662. alter table tb_ErpTwoSalesOrder add Tsorder_CustomerNumber nvarchar(50)
  663. end
  664. GO
  665. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_TwoSalesOrder')
  666. BEGIN
  667. DROP VIEW [dbo].Vw_TwoSalesOrder
  668. END
  669. GO
  670. Create view [dbo].Vw_TwoSalesOrder
  671. as
  672. SELECT
  673. dbo.tb_ErpTwoSalesOrder.ID,
  674. Tsorder_Number,
  675. Tsorder_Name,
  676. (select Cus_Name from tb_ErpCustomer where Tsorder_CustomerNumber=Cus_CustomerNumber) as Tsorder_CustomerName,
  677. (select Cus_Telephone from tb_ErpCustomer where Tsorder_CustomerNumber=Cus_CustomerNumber) as Tsorder_Telephone,
  678. (select Cus_NamePinyin from tb_ErpCustomer where Tsorder_CustomerNumber=Cus_CustomerNumber) as Cus_NamePinyin,
  679. Tsorder_Money,
  680. Tsorder_Quantity,
  681. Tsorder_Category,
  682. Tsorder_OpenSingle,
  683. Tsorder_PersonHandling,
  684. Tsorder_Remark,
  685. Tsorder_CreateDatetime,
  686. Tsorder_UpdateDatetime,
  687. dbo.fn_CheckUserIDGetUserName(Tsorder_OpenSingle) AS [User_Name],
  688. dbo.fn_CheckUserIDGetUserName(Tsorder_PersonHandling) AS Tsorder_PersonHandlingName,
  689. dbo.fn_GetClassCodeToName(Tsorder_Category,Tsorder_Category) AS Tsorder_CategoryName,
  690. Tsorder_CustomerNumber
  691. FROM dbo.tb_ErpTwoSalesOrder
  692. GO
  693. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_OrdersWagePaymentRecords')
  694. BEGIN
  695. DROP VIEW [dbo].Vw_OrdersWagePaymentRecords
  696. END
  697. GO
  698. Create view [dbo].Vw_OrdersWagePaymentRecords
  699. as
  700. SELECT
  701. tb_ErpPayment.ID,
  702. Pay_OrdNumber,
  703. Pay_AmountOf,
  704. Pay_OpenSingle,
  705. Pay_ThePayee,
  706. Pay_PaymentMethod,
  707. Pay_OrdersLocation,
  708. Pay_ReceivableProject,
  709. Pay_Remark,
  710. convert(varchar(10),Pay_CreateDatetime,120) as Pay_CreateDatetime,
  711. Pay_Category,
  712. Pay_TwoPinsCategory,
  713. dbo.fn_CheckUserIDGetUserName(Pay_OpenSingle) AS Pay_UserName,
  714. dbo.fn_CheckUserIDGetUserName(Pay_ThePayee) AS Pay_ThePayeeName,
  715. dbo.fn_GetClassCodeToName(Pay_PaymentMethod, Pay_PaymentMethod) AS Pay_PaymentMethodName,
  716. dbo.fn_GetClassCodeToName(Pay_TwoPinsCategory, Pay_TwoPinsCategory) AS Pay_TwoPinsCategoryName,
  717. Pay_FinancialAuditdPeople,
  718. Pay_FinancialAudit,
  719. dbo.fn_CheckUserIDGetUserName(Pay_FinancialAuditdPeople)AS Pay_FinancialAuditdPeopleName,
  720. Pay_ShootingName,
  721. Pay_Type,
  722. Ord_DividedShop,
  723. Ord_Type,
  724. Cus_Name as Ord_CustomerName1,
  725. (select Tsorder_Name from Vw_TwoSalesOrder where Pay_OrdNumber= Tsorder_Number) as Tsorder_Name,
  726. (select Tsorder_CustomerName from Vw_TwoSalesOrder where Pay_OrdNumber= Tsorder_Number) as Tsorder_CustomerName,
  727. (select Cus_Name from View_DressSaleRentalOrder where Pay_OrdNumber=Dsro_Number) as Cus_Name,
  728. Ord_CreateDatetime,
  729. Ord_SeriesName,
  730. Ord_PhotographyCategory
  731. FROM tb_ErpPayment
  732. left join Vw_Customer_PaymentOrders on Pay_OrdNumber=Ord_Number
  733. GO
  734. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_StaffPerformance_OrdersPerson')
  735. BEGIN
  736. DROP VIEW [dbo].Vw_StaffPerformance_OrdersPerson
  737. END
  738. GO
  739. create View Vw_StaffPerformance_OrdersPerson
  740. as
  741. SELECT
  742. ID
  743. ,Pay_OrdNumber as 订单号
  744. ,Pay_ShootingName as 拍摄阶段
  745. ,Pay_Category as 收款类别
  746. ,Pay_TwoPinsCategory as 二销类别编号
  747. ,dbo.fn_GetClassCodeToName(Pay_TwoPinsCategory, Pay_TwoPinsCategory) AS 二销类别名称
  748. ,Pay_AmountOf as 收款金额
  749. ,Pay_OpenSingle as 接单人编号
  750. , dbo.fn_CheckUserIDGetUserName(Pay_OpenSingle) AS 接单人名称
  751. ,Pay_ThePayee as 收款人编号
  752. ,dbo.fn_CheckUserIDGetUserName(Pay_ThePayee) AS 收款人名称
  753. ,Pay_PaymentMethod as 付款方式编号
  754. ,dbo.fn_GetClassCodeToName(Pay_PaymentMethod, Pay_PaymentMethod) AS 付款方式名称
  755. ,Pay_OrdersLocation as 接单地点
  756. ,Pay_ReceivableProject as 收款项目
  757. ,Pay_FinancialAudit as 审核状态
  758. ,Pay_FinancialAuditdPeople as 审核人
  759. ,Pay_Remark as 备注
  760. ,Pay_CreateDatetime as 收款时间
  761. ,Pay_Type as 收款类型
  762. ,(case Pay_Type
  763. when 0 then (select Cus_Name from tempTB_AggregationCustomer where Pay_OrdNumber=GP_OrderNumber)
  764. when 1 then (select Tsorder_CustomerName from Vw_TwoSalesOrder where Pay_OrdNumber=Tsorder_Number)
  765. when 2 then (select Cus_Name from View_DressSaleRentalOrder where Pay_OrdNumber=Dsro_Number)
  766. else '' end) as '客户名称'
  767. ,(case Pay_Type
  768. when 0 then (select Ord_PhotographyCategory from tb_ErpOrder where Pay_OrdNumber=Ord_Number)
  769. else '' end) as '套系类别'
  770. ,(case Pay_Type
  771. when 0 then (select Ord_SeriesName from tb_ErpOrder where Pay_OrdNumber=Ord_Number)
  772. else '' end) as '套系名称'
  773. ,(case Pay_Type
  774. when 0 then (select Ord_SeriesPrice from tb_ErpOrder where Pay_OrdNumber=Ord_Number)
  775. when 1 then (select Tsorder_Money from Vw_TwoSalesOrder where Pay_OrdNumber=Tsorder_Number)
  776. when 2 then (select Dsro_Amount from View_DressSaleRentalOrder where Pay_OrdNumber=Dsro_Number)
  777. end) as '应收金额'
  778. ,(case Pay_Type
  779. when 0 then (dbo.fn_GetClassCodeToName(Pay_TwoPinsCategory, Pay_TwoPinsCategory))
  780. when 1 then (dbo.fn_GetClassCodeToName(Pay_TwoPinsCategory, Pay_TwoPinsCategory))
  781. when 2 then Pay_ReceivableProject
  782. end) as '项目名称'
  783. FROM tb_ErpPayment
  784. GO
  785. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_StaffPerformance_Photograph')
  786. BEGIN
  787. DROP VIEW [dbo].Vw_StaffPerformance_Photograph
  788. END
  789. GO
  790. create View Vw_StaffPerformance_Photograph
  791. as
  792. SELECT
  793. Ordv_Number as 主订单
  794. ,Ordv_ViceNumber as 副订单
  795. ,(select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number) as 订单类型
  796. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  797. when 0 then (select stuff((select ','+ Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  798. when 1 then (select stuff((select ','+ Ordpg_Sights from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  799. when 2 then (select stuff((select ','+ Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  800. else '' end) as 拍摄名称
  801. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  802. when 0 then (select max(Ordpg_PhotographyTime) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number)
  803. when 1 then (select max(Ordpg_PhotographyTime) from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber)
  804. when 2 then (select max(Ordpg_PhotographyTime) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number)
  805. else '' end) as 最后拍摄时间
  806. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  807. when 0 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  808. when 1 then (select count(id) as id from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  809. when 2 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  810. else '' end) as 未拍个数
  811. ,(case Ordv_FilmSelectionStatus when 1 then 'OK' else '未选' end) as 选片状态
  812. ,Ordv_FilmSelectionTime as 选片时间
  813. ,(case when (select Count(*) from (select [OPlist_PickupStatus] from [tb_ErpOrderProductList] where [OPlist_ViceNumber]=Ordv_ViceNumber and OPlist_Type = '2' and [OPlist_PickupStatus] = '0') as ta)>0 then '未取' else 'OK' end) AS 取件状态
  814. ,(select top 1 OPlist_PickupTime from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = '2' and OPlist_PickupTime is not null order by OPlist_PickupTime) AS 取件日期
  815. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  816. when 0 then (select stuff((select ','+ Ordpg_Photographer from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  817. when 1 then (select stuff((select ','+ Ordpg_Photographer from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  818. when 2 then (select stuff((select ','+ Ordpg_Photographer from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  819. else '' end) as 主摄影师ID
  820. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  821. when 0 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  822. when 1 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  823. when 2 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  824. else '' end) as 主摄影师名称
  825. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  826. when 0 then (select stuff((select ','+ Ordpg_PhotographyAssistant from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  827. when 1 then (select stuff((select ','+ Ordpg_PhotographyAssistant from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  828. when 2 then (select stuff((select ','+ Ordpg_PhotographyAssistant from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  829. else '' end) as 摄影助理ID
  830. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  831. when 0 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_PhotographyAssistant) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  832. when 1 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_PhotographyAssistant) from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  833. when 2 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_PhotographyAssistant) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  834. else '' end) as 摄影助理名称
  835. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  836. when 0 then (select stuff((select ','+ Ordpg_MakeupArtist from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  837. when 1 then (select stuff((select ','+ Ordpg_MakeupArtist from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  838. when 2 then (select stuff((select ','+ Ordpg_MakeupArtist from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  839. else '' end) as 主化妆ID
  840. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  841. when 0 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupArtist) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  842. when 1 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupArtist) from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  843. when 2 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupArtist) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  844. else '' end) as 主化妆名称
  845. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  846. when 0 then (select stuff((select ','+ Ordpg_MakeupAssistant from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  847. when 1 then (select stuff((select ','+ Ordpg_MakeupAssistant from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  848. when 2 then (select stuff((select ','+ Ordpg_MakeupAssistant from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  849. else '' end) as 化妆助理ID
  850. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  851. when 0 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupAssistant) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  852. when 1 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupAssistant) from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  853. when 2 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupAssistant) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  854. else '' end) as 化妆助理名称
  855. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  856. when 0 then (select stuff((select ','+ Ordpg_BootDivision from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  857. when 1 then (select stuff((select ','+ Ordpg_BootDivision from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  858. when 2 then (select stuff((select ','+ Ordpg_BootDivision from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  859. else '' end) as 引导师ID
  860. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  861. when 0 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_BootDivision) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  862. when 1 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_BootDivision) from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  863. when 2 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_BootDivision) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  864. else '' end) as 引导师名称
  865. ,Vw_StaffPerformance_OrdersPerson.ID
  866. ,订单号
  867. ,拍摄阶段
  868. ,收款类别
  869. ,二销类别编号
  870. ,二销类别名称
  871. ,收款金额
  872. ,接单人编号
  873. ,接单人名称
  874. ,收款人编号
  875. ,收款人名称
  876. ,付款方式编号
  877. ,付款方式名称
  878. ,接单地点
  879. ,收款项目
  880. ,审核状态
  881. ,审核人
  882. ,备注
  883. ,收款时间
  884. ,收款类型
  885. ,客户名称
  886. ,套系类别
  887. ,套系名称
  888. ,应收金额
  889. ,项目名称
  890. FROM tb_ErpOrderDigital
  891. left join Vw_StaffPerformance_OrdersPerson on Ordv_Number=订单号
  892. where 订单号 is not null
  893. GO
  894. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_StaffPerformance_MemberCardRechargeRecord')
  895. BEGIN
  896. DROP VIEW [dbo].Vw_StaffPerformance_MemberCardRechargeRecord
  897. END
  898. GO
  899. create View Vw_StaffPerformance_MemberCardRechargeRecord
  900. as
  901. SELECT ID
  902. ,Mcrr_Number as 会员编号
  903. ,Mcrr_RechargeNumber as 充值编号
  904. ,Mcrr_RechargeName as 充值名称
  905. ,Mcrr_RechargeAmount as 充值金额
  906. ,Mcrr_DonateAmount as 赠送金额
  907. ,Mcrr_DonateDiscount as 消费折扣
  908. ,Mcrr_PaymentMethod as 支付方式编号
  909. ,dbo.fn_GetClassCodeToName(Mcrr_PaymentMethod, Mcrr_PaymentMethod) as 支付方式名称
  910. ,Mcrr_OrderPerson as 接单人编号
  911. ,dbo.fn_CheckUserIDGetUserName(Mcrr_OrderPerson) AS 接单人名称
  912. ,convert(varchar(10),Mcrr_CreateDatetime,120) as 创建时间
  913. ,Mcrr_CreateName as 创建人编号
  914. ,dbo.fn_CheckUserIDGetUserName(Mcrr_CreateName) AS 创建人名称
  915. ,(select Cus_Name from tb_ErpCustomer where Cus_CustomerNumber=(select Mc_CustomerNumber from tb_ErpMemberCard where Mcrr_Number=Mc_Number)) as 客户姓名
  916. FROM tb_ErpMemberCardRechargeRecord
  917. GO
  918. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_ErpMemberCardPayment')
  919. BEGIN
  920. DROP VIEW [dbo].Vw_ErpMemberCardPayment
  921. END
  922. GO
  923. create View Vw_ErpMemberCardPayment
  924. as
  925. SELECT ID
  926. ,Mcpt_PaymentNumber as 收款编号
  927. ,Mcpt_Number as 会员卡编号
  928. ,Mcpt_PaymentType as 收款类型
  929. ,Mcpt_PaymentAmount as 收款金额
  930. ,Mcpt_PaymentMethod as 付款方式编号
  931. ,dbo.fn_GetClassCodeToName(Mcpt_PaymentMethod, Mcpt_PaymentMethod) as 支付方式名称
  932. ,Mcpt_PackageClass as 服务套系类别编号
  933. ,(case Mcpt_PackageClass
  934. when '' then (select stuff((select ','+ Mcpcd_ServiceContent from tb_ErpMemberCardPaymentContentDetail where Mcpt_PaymentNumber=Mcpcd_PaymentNumber for xml path('')),1,1,''))
  935. else (select MscPs_PackageName from tb_ErpMemberCardServicePackageSet where Mcpt_PackageClass=MscPs_PackageNumber) end) as 服务套系类别名称
  936. ,Mcpt_PackagePrice as 服务套系价格
  937. ,Mcpt_Discount as 优惠折扣
  938. ,Mcpt_OrderPerson as 接单人编号
  939. ,dbo.fn_CheckUserIDGetUserName(Mcpt_OrderPerson) AS 接单人名称
  940. ,Mcpt_PaymentRemark as 收款备注
  941. ,Mcpt_FinancialAudit 财务审核状态
  942. ,Mcpt_FinancialAuditName as 账务审核人
  943. ,Mcpt_FinancialAuditDateTime as 财务审核时间
  944. ,Mcpt_FinancialAuditRemark as 账务审核备注
  945. ,convert(varchar(10),Mcpt_CreateDatetime,120) as 创建日期
  946. ,Mcpt_CreateName as 创建人编号
  947. ,dbo.fn_CheckUserIDGetUserName(Mcpt_CreateName) AS 创建人名称
  948. ,(select Cus_Name from tb_ErpCustomer where Cus_CustomerNumber=(select Mc_CustomerNumber from tb_ErpMemberCard where Mcpt_Number=Mc_Number)) as 客户姓名
  949. FROM tb_ErpMemberCardPayment
  950. GO
  951. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_ReportTime')
  952. BEGIN
  953. DROP VIEW [dbo].Vw_ReportTime
  954. END
  955. GO
  956. create View Vw_ReportTime
  957. as
  958. with t as(
  959. select distinct convert(varchar(10),isnull(Vw_OrdersWagePaymentRecords.Pay_CreateDatetime,View_ErpOtherIncomeAndExpenses.Oiae_IEDatetime),120) as Pay_CreateDatetimes
  960. ,Pay_OrdNumber,Pay_CreateDatetime,Oiae_ProjectName,Oiae_IEDatetime
  961. from Vw_OrdersWagePaymentRecords
  962. full join View_ErpOtherIncomeAndExpenses on Vw_OrdersWagePaymentRecords.Pay_CreateDatetime=View_ErpOtherIncomeAndExpenses.Oiae_IEDatetime
  963. )
  964. , t2 as(
  965. select distinct convert(varchar(10),isnull(t.Pay_CreateDatetimes,Vw_ErpMemberCardPayment.创建日期),120) as Pay_CreateDatetimes from t
  966. full join Vw_ErpMemberCardPayment on t.Pay_CreateDatetimes=Vw_ErpMemberCardPayment.创建日期
  967. )
  968. select distinct convert(varchar(10),isnull(t2.Pay_CreateDatetimes,Vw_StaffPerformance_MemberCardRechargeRecord.创建时间),120) as Pay_CreateDatetimes from t2
  969. full join Vw_StaffPerformance_MemberCardRechargeRecord on t2.Pay_CreateDatetimes=Vw_StaffPerformance_MemberCardRechargeRecord.创建时间
  970. GO
  971. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_MonthlyReport')
  972. BEGIN
  973. DROP VIEW [dbo].Vw_MonthlyReport
  974. END
  975. GO
  976. create View Vw_MonthlyReport
  977. as
  978. select
  979. Pay_CreateDatetimes
  980. ,(select sum(Pay_AmountOf) from tb_ErpPayment where (Pay_Category='全款' or Pay_Category='预约收款') and Pay_PaymentMethod!='BEBACCAFEGECFBJFD' and Pay_CreateDatetime>=Pay_CreateDatetimes and Pay_CreateDatetime<=Pay_CreateDatetimes+' 23:59:59.000') as DayOrdersIncome
  981. , (select sum(Pay_AmountOf) from tb_ErpPayment where Pay_Category='预约补款' and Pay_PaymentMethod!='BEBACCAFEGECFBJFD' and Pay_CreateDatetime>=Pay_CreateDatetimes and Pay_CreateDatetime<=Pay_CreateDatetimes+' 23:59:59.000') as DayReplenishmentIncome
  982. ,(select sum(Pay_AmountOf) from tb_ErpPayment where Pay_Category='后期收款' and Pay_PaymentMethod!='BEBACCAFEGECFBJFD' and Pay_CreateDatetime>=Pay_CreateDatetimes and Pay_CreateDatetime<=Pay_CreateDatetimes+' 23:59:59.000') as DayLateStageIncome
  983. , (select sum(Oiae_Money) from tb_ErpOtherIncomeAndExpenses where Oiae_Type='收入' and Oiae_PaymentMethod!='BEBACCAFEGECFBJFD' and Oiae_IEDatetime>=Pay_CreateDatetimes and Oiae_IEDatetime<=Pay_CreateDatetimes+' 23:59:59.000') as DayOtherIncome
  984. ,(select sum(Mcrr_RechargeAmount) from tb_ErpMemberCardRechargeRecord where Mcrr_CreateDatetime>=Pay_CreateDatetimes and Mcrr_CreateDatetime<=Pay_CreateDatetimes+' 23:59:59.000') as DayMemberIncome
  985. ,(select sum(Ord_SeriesPrice) from tb_ErpOrder where ord_class='1' and Ord_CreateDatetime>=Pay_CreateDatetimes and Ord_CreateDatetime<=Pay_CreateDatetimes+' 23:59:59.000') as DayEarlyPerformance
  986. ,(select sum(Plu_Amount) from tb_ErpPlusPickItems where Plu_CreateTime>=Pay_CreateDatetimes and Plu_CreateTime<=Pay_CreateDatetimes+' 23:59:59.000') as DayPluslatepickPerformance
  987. ,(select sum(Tsorder_Money) from tb_ErpTwoSalesOrder where Tsorder_CreateDatetime>=Pay_CreateDatetimes and Tsorder_CreateDatetime<=Pay_CreateDatetimes+' 23:59:59.000') as DayOtherPerformance
  988. , (select sum(Oiae_Money) from tb_ErpOtherIncomeAndExpenses where Oiae_Type='支出' and Oiae_IEDatetime>=Pay_CreateDatetimes and Oiae_IEDatetime<=Pay_CreateDatetimes+' 23:59:59.000') as DayExpenditure
  989. ,(select sum(Mcpt_PaymentAmount) from tb_ErpMemberCardPayment where Mcpt_CreateDatetime>=Pay_CreateDatetimes and Mcpt_CreateDatetime<=Pay_CreateDatetimes+' 23:59:59.000') as DayMemberCardPaymentIncome
  990. from
  991. (
  992. select Pay_CreateDatetimes from Vw_ReportTime
  993. ) as MonthlyReport
  994. group by Pay_CreateDatetimes
  995. GO
  996. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_YearReport')
  997. BEGIN
  998. DROP VIEW [dbo].Vw_YearReport
  999. END
  1000. GO
  1001. create View Vw_YearReport
  1002. as
  1003. select
  1004. Pay_CreateDatetimes
  1005. ,(select sum(Pay_AmountOf) from tb_ErpPayment where (Pay_Category='全款' or Pay_Category='预约收款') and Pay_PaymentMethod!='BEBACCAFEGECFBJFD' and convert(varchar,Pay_CreateDatetime,120) like '%'+Pay_CreateDatetimes+'%') as DayOrdersIncome
  1006. , (select sum(Pay_AmountOf) from tb_ErpPayment where Pay_Category='预约补款' and Pay_PaymentMethod!='BEBACCAFEGECFBJFD' and convert(varchar,Pay_CreateDatetime,120) like '%'+Pay_CreateDatetimes+'%') as DayReplenishmentIncome
  1007. ,(select sum(Pay_AmountOf) from tb_ErpPayment where Pay_Category='后期收款' and Pay_PaymentMethod!='BEBACCAFEGECFBJFD' and convert(varchar,Pay_CreateDatetime,120) like '%'+Pay_CreateDatetimes+'%') as DayLateStageIncome
  1008. , (select sum(Oiae_Money) from tb_ErpOtherIncomeAndExpenses where Oiae_Type='收入' and Oiae_PaymentMethod!='BEBACCAFEGECFBJFD' and convert(varchar,Oiae_IEDatetime,120) like '%'+Pay_CreateDatetimes+'%') as DayOtherIncome
  1009. ,(select sum(Mcrr_RechargeAmount) from tb_ErpMemberCardRechargeRecord where convert(varchar,Mcrr_CreateDatetime,120) like '%'+Pay_CreateDatetimes+'%') as DayMemberIncome
  1010. ,(select sum(Ord_SeriesPrice) from tb_ErpOrder where ord_class='1' and convert(varchar,Ord_CreateDatetime,120) like '%'+Pay_CreateDatetimes+'%') as DayEarlyPerformance
  1011. ,(select sum(Plu_Amount) from tb_ErpPlusPickItems where convert(varchar,Plu_CreateTime,120) like '%'+Pay_CreateDatetimes+'%') as DayPluslatepickPerformance
  1012. ,(select sum(Tsorder_Money) from tb_ErpTwoSalesOrder where convert(varchar,Tsorder_CreateDatetime,120) like '%'+Pay_CreateDatetimes+'%') as DayOtherPerformance
  1013. , (select sum(Oiae_Money) from tb_ErpOtherIncomeAndExpenses where Oiae_Type='支出' and convert(varchar,Oiae_IEDatetime,120) like '%'+Pay_CreateDatetimes+'%') as DayExpenditure
  1014. ,(select sum(Mcpt_PaymentAmount) from tb_ErpMemberCardPayment where convert(varchar,Mcpt_CreateDatetime,120) like '%'+Pay_CreateDatetimes+'%') as DayMemberCardPaymentIncome
  1015. from
  1016. (
  1017. select convert(varchar(7),Pay_CreateDatetimes,120) as Pay_CreateDatetimes from Vw_ReportTime
  1018. ) as YearReport
  1019. group by Pay_CreateDatetimes
  1020. GO
  1021. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_ProcessStatus')
  1022. BEGIN
  1023. DROP VIEW [dbo].Vw_ProcessStatus
  1024. END
  1025. GO
  1026. create View [dbo].[Vw_ProcessStatus]
  1027. as
  1028. Select
  1029. ID
  1030. ,Ordv_Number as 主订单号
  1031. ,Ordv_ViceNumber as 副订单号
  1032. ,Ordv_DigitalNumber as 拍摄次数
  1033. ,(select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number) as 订单类型
  1034. ,(select Ord_Class from tb_ErpOrder where Ordv_Number=Ord_Number) as 订单类别
  1035. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  1036. when 1 then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber)
  1037. else (select stuff((select ','+ Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,'')) end) as 拍摄名称
  1038. ,(select Ord_CreateDateTime from tb_ErpOrder where Ordv_Number=Ord_Number) as 预选时间
  1039. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  1040. when 0 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  1041. when 1 then (select count(id) as id from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  1042. when 2 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  1043. else '' end) as 未拍个数
  1044. , (case Ordv_EarlyRepairStatus when 2 then 'OK' else '未修'end ) as 初修状态
  1045. , (case Ordv_FilmSelectionStatus when 1 then 'OK' else '未选'end ) as 选片状态
  1046. , (case Ordv_RefinementStatus when 2 then 'OK' else '未修'end ) as 精修状态
  1047. , (case Ordv_DesignerStatus when 2 then 'OK' else '未设计'end ) as 设计状态
  1048. , (case Ordv_LookDesignStatus when 1 then 'OK' else '未看'end ) as 看设计状态
  1049. ,(select count(id) as id from tb_ErpOrderProductList where OPlist_Type=2 and OPlist_ViceNumber=Ordv_ViceNumber and OPlist_SendStatus=0) as 未发出个数
  1050. ,(select count(id) as id from tb_ErpOrderProductList where OPlist_Type=2 and OPlist_ViceNumber=Ordv_ViceNumber and OPlist_CompletedStatus=0) as 未完成个数
  1051. ,(case when (select Count(*) from (select [OPlist_PickupStatus] from [tb_ErpOrderProductList] where [OPlist_ViceNumber]=Ordv_ViceNumber and OPlist_Type = '2' and [OPlist_PickupStatus] = '0') as ta)>0 then '未取' else 'OK' end) AS 取件状态
  1052. from tb_ErpOrderDigital
  1053. GO
  1054. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_ErpCustomersTrackRecord')
  1055. BEGIN
  1056. DROP VIEW [dbo].Vw_ErpCustomersTrackRecord
  1057. END
  1058. GO
  1059. create View Vw_ErpCustomersTrackRecord
  1060. as
  1061. SELECT id
  1062. ,TR_CustomerGroupID as 客户组
  1063. ,TR_CustomerID as 客户ID
  1064. ,(select Cus_Name from tb_ErpCustomer where TR_CustomerID=Cus_CustomerNumber) as 客户姓名
  1065. ,TR_TraceWay as 沟通方式
  1066. ,TR_TraceType as 沟通类型
  1067. ,TR_SpecificMatters
  1068. ,TR_Communicationstatus as 沟通状态
  1069. ,TR_TraceDetailedly
  1070. ,TR_CallRecording as 录音路径文件
  1071. ,TR_Remark as 备注
  1072. ,TR_TraceDateTime as 沟通日期
  1073. ,TR_TraceTimeLength as 沟通时长
  1074. ,TR_TracePersonID as 跟踪人员ID
  1075. ,(select User_Name from tb_ErpUser where TR_TracePersonID=User_EmployeeID) as 跟踪人员姓名
  1076. ,TR_CreateDateTime as 创建时间
  1077. FROM dbo.tb_ErpCustomersTrackRecord
  1078. GO